package tinhluong;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CongTy {
	private List<NhanVien> listNV = new ArrayList<NhanVien>();
	
	//gettor
	public List<NhanVien> getNhanVien() {
		return listNV;
	}
	
	//settor
	public void setNhanVien(List<NhanVien> dsNV) {
		if((dsNV != null) && (dsNV.size() > 0)) {
			this.listNV = dsNV;
		}
	}
	
	//xuat bao cao
	public void xuatBaoCao(String file) {
		try {
			FileOutputStream fos = new FileOutputStream(file);
			DataOutputStream dos = new DataOutputStream(fos);
			
			for(int i = 0; i < listNV.size(); i++) {
				System.out.println("Bang bao cao luong: ");
				try {

					System.out.println("Ma so thue: ");
					dos.writeUTF(listNV.get(i).getMaSoThue());
					
					System.out.println("Tien luong: ");
					dos.writeDouble(listNV.get(i).getTienLuong());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void docBaoCao(String file) {
		FileInputStream fis;
		
		try {
			fis = new FileInputStream(file);
			DataInputStream dis = new DataInputStream(fis);
			
			for(NhanVien nv: listNV) {
				try {
					System.out.print("Ma so thue: " + dis.readUTF());
					System.out.print("Luong: " + dis.readDouble());
				}
				catch (Exception e) {
					System.out.print("");
				}
			}
		}
		catch (Exception e) {
			System.out.println("Error read file.");
		}
	}
}
